#' joining ha and price data
#'
#' This function can join price and ha info
#' @param tabln.vec basic data provided by \code{\link{loadData}}
#' @param pty type code of properties.The defalut is 11 indiciting housing
#' @export
#' @return data including ha info and ha price
ppsale<-function(tabln.vec=NULL,pty=11)
{
    if(is.null(tabln.vec)){
        stop('must provide a tabln.vec!!!')
    }
    library(dplyr)
    price_sale<-tabln.vec$ha_price%>%filter(proptype==pty)%>%
        dplyr::select(one_of(c('ymid','ha_code',
                               'saleprice','salebldgarea','rentprice','rentbldgarea'
                               ,'year','month')))%>%na.omit
    price_sale <- price_sale[!duplicated(price_sale),]
    if (nrow(price_sale) > 0)
    {
        price_sale[price_sale==0] <- NA
    }
    ppi_sale<-merge(price_sale,tabln.vec$ha_info.sp,by='ha_code',all.y=T)
    ppi_sale<-ppi_sale%>%
        # mutate(year=floor(ymid/12),
        # month=ifelse(!ymid%%12,12,ymid%%12))%>%
        group_by(ha_code,x,y,year,month)%>%
        summarise(saleprice=mean(saleprice,na.rm=T),rentprice=mean(rentprice,na.rm=T))%>%
        as.data.frame()
    ppi_sale[ppi_sale=='NaN'] <- NA
    return(ppi_sale)
}
